/**
 * \file rtc.h
 * \brief Real-time Clock Driver
 * \author Radim Badsi <radim.badsi@polytech.univ-montp2.fr>
 * \date 9/07/2010
 */

#ifndef RTC_H
#define RTC_H

#include "smallsatos.h"

/* RTC registers */
#define		PCF8563_WADDR		0xA2
#define		PCF8563_RADDR		0xA3
#define		control_status_1	0x00
#define		control_status_2	0x01
#define		CLKOUT_control		0x0D
#define		timer_control		0x0E
#define		timer				0x0F

typedef enum
{
	RTC_TIMER=0x0F, RTC_SECONDES=0x02, RTC_MINUTES=0x03, 
	RTC_HEURES=0x04, RTC_JOURS=0x05, RTC_SEMAINES=0x06,
	RTC_MOIS=0x07, RTC_ANNEES=0x08
} commande_rtc_t;

typedef INT32U time_t;

INT8U pcf8563_get(commande_rtc_t reg);
void pcf8563_put(commande_rtc_t reg, INT8U data);
void init_rtc(void);
char bcd_to_char (char bcd);
void update_system_time(void);
void write_time(INT16U ad);

void rtc_task (void *pdata);
OS_EVENT* get_rtc_lock (void);
void set_system_time (INT32U now);
#endif